#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

// https://leetcode.cn/problems/subarray-sum-equals-k/?envType=study-plan-v2&envId=top-100-liked

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        unordered_map<int, int> prefix{{0,1}};
        int sum = 0;
        int ans = 0;
        for(auto num : nums){
            sum += num;
            ans += ((prefix.find(sum - k) != prefix.end()) ? prefix[sum - k] : 0);
            prefix[sum]++;
        }
        return ans;
    }
};

int main()
{
    return 0;
}